<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        添加原料数据字典
    </h1>
</section>
<section class="content">
    <form id="materialForm" class="form-horizontal">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3>原料数据字典基本信息</h3>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="mdPid" class="col-sm-2 control-label">分类</label>
                                    <div class="col-sm-6">
                                        <select id="mdPid" class="form-control select2"
                                                name="mdPid" style="width: 100%;">
                                            <option value="">请选择</option>
                                            <option value="1">板材</option>
                                            <option value="2">型材</option>
                                            <option value="3">通用</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="mdTypeNum" class="col-sm-2 control-label">类别</label>
                                    <div class="col-sm-6">
                                        <select id="mdTypeNum" class="form-control select2"
                                                name="mdTypeNum" style="width: 100%;">
                                            <option value="">请选择</option>
                                            <option value="1000">类型</option>
                                            <option value="2000">材质</option>
                                            <option value="3000">规格</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">内容</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control"
                                               id="mdName" name="mdName" placeholder="请输入内容" autocomplete="off">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">编码</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control"
                                               id="mdMatCode" name="mdMatCode" placeholder="请输入编码"
                                               autocomplete="off" readonly="readonly">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="mdFormulaType" class="col-sm-2 control-label">重量公式</label>
                                    <div class="col-sm-10">
                                        <select id="mdFormulaType" class="form-control select2" name="mdFormulaType"
                                                style="width: 100%;">
                                            <option value="">请选择</option>
                                            <option value="">&nbsp;</option>
                                            <option value="1">
                                                （规格*宽度*长度*数量*7.85/1000）-（(规格-2*米重/厚度)*（宽度-2*米重/厚度）*7.85/1000*数量*长度
                                            </option>
                                            <option value="2">规格*规格*长度*数量*0.00617</option>
                                            <option value="3">长度*数量*米重/厚度</option>
                                            <option value="4">（规格-宽度）*宽度*0.02466*长度*数量</option>
                                            <option value="5">规格*宽度*长度*2.7/1000000*数量</option>
                                            <option value="6">规格*宽度*长度*7.85/1000000*数量</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <button type="button" id="btn_create" class="btn btn-info pull-right">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
<div th:include="include :: footer"></div>
<script>

    $(function () {
        // 验证初始化
        js.validate.init("materialForm", {
            fields: {
                mdName: {validators: {notEmpty: {message: '请输入内容'}}},
                mdTypeNum: {validators: {notEmpty: {message: '请选择类别'}}},
                mdMatCode: {validators: {notEmpty: {message: '请输入内容简码'}}},
                mdPid: {validators: {notEmpty: {message: '请选择分类'}}}
            }
        });

        // 创建原料名称
        $("#btn_create").click(function () {

            js.validSubmit({
                formId: "materialForm",
                url: ctx + "basic/materialdictionary/save",
                data: new FormData($("#materialForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        location.href = ctx + "basic/materialdictionary/page";
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });

        // 选择分类和类别，联动编码
        $("#mdTypeNum").change(function () {
                if ($('#mdTypeNum option:selected').val() === "") {
                    return;
                }
                if ($('#mdTypeNum option:selected').val() === "1000") {

                    $("#mdFormulaType").removeAttr("disabled");
                } else {
                    $("#mdFormulaType").val("");
                    $("#mdFormulaType").attr("disabled", "disabled")
                }
                js.get({
                    url: ctx + "basic/materialdictionary/getMaterialCode",
                    data: {mdTypeNum: $('#mdTypeNum option:selected').val()},
                    success: function (result) {
                        $("#mdMatCode").val(result.data);
                    }
                });
            }
        );

    });
</script>
</body>
</html>
